#include <chrono>
#include <spdlog/spdlog.h>
#define STB_IMAGE_IMPLEMENTATION
#include <stb/stb_image.h>
#include <stdexcept>
#include <thread>

#include <Encoder.hpp>

int imgHeight, imgWidth, imgChannel;

int main() {
  spdlog::info(">>>>>> Initialized");
  Encoder coder("srt://"
                "127.0.0.1:10080?streamid=#!::r="
                "live/livestream,m=publish");

  unsigned char *img =
      stbi_load("test.png", &imgWidth, &imgHeight, &imgChannel, 0);

  spdlog::info(">>>>>> Working");
  coder.StartStream(imgWidth, imgHeight, []() -> BaseEncoder::ImageType {
    switch (imgChannel) {
    case 1:
      return BaseEncoder::ImageType::GREY;
    case 3:
      return BaseEncoder::ImageType::RGB8;
    default:
      throw std::runtime_error("Unknow Image Type");
    }
  }());
  while (true) {
    coder.InputImage(img);
    std::this_thread::sleep_for(std::chrono::milliseconds(33));
  }
  coder.EndStream();
  stbi_image_free(img);
}
